<script setup lang="ts">
import preview from "../application/edit/fourthStep/index.vue";

import { useRouter } from "vue-router";
import { reactive, ref } from "vue";
import type { FormInstance, FormRules } from "element-plus";

const router = useRouter();
let show = router.currentRoute?.value?.query?.id || "";
const formRef = ref();
const form = reactive({
  status: "",
  desc: ""
});
const rules = {
  status: [{ required: true, message: "请选择审批结果", trigger: "change" }],
  desc: [{ required: true, message: "请填写审批意见", trigger: "blur" }]
};
const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  await formEl.validate((valid, fields) => {
    if (valid) {
      router.push({
        name: "projectCarry"
      });
    } else {
      console.log("error submit!", fields);
    }
  });
};

const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  formEl.resetFields();
  router.push({
    name: "projectExamine"
  });
};
const goBack = () => {
  router.push({
    name: "projectExamine"
  });
};
</script>

<template>
  <el-card :body-style="{ padding: '10px' }">
    <template #header>
      <el-page-header @back="goBack">
        <template #content>
          <span class="mr-3 text-large font-600"> 社区工作者关爱服务项目 </span>
        </template>
      </el-page-header>
    </template>
    <preview :show="true" />
    <div v-if="show" class="p-[20px]">
      <el-form :model="form" :rules="rules" ref="formRef">
        <el-form-item label="审批结果" class="w-[240px]" prop="status">
          <el-select v-model="form.status" placeholder="请选择审批结果">
            <el-option label="通过" value="pass"></el-option>
            <el-option label="拒绝" value="refuse"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审批意见" prop="desc" class="w-[500px]">
          <el-input
            type="textarea"
            v-model="form.desc"
            placeholder="请输入审批意见"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm(formRef)"
            >提交</el-button
          >
          <el-button @click="resetForm(formRef)">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </el-card>
</template>

<style lang="scss" scoped></style>
